package com.muqi.app.user.widget;



import com.muqi.app.qlearn.student.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public class ClubWindow extends PopupWindow implements OnClickListener {
	private View conentView;
	private Context mContext;
	private String type[]={"day","week","month","year","all"};
	
	public interface ClickClubWindowListener{
		void onClickClubWindowListener(int time,String typeName);
	}
	
	private ClickClubWindowListener clickClubWindowListener;
	
	@SuppressWarnings("deprecation")
	public ClubWindow(final Activity context, ClickClubWindowListener clickClubWindowListener) {
		this.clickClubWindowListener = clickClubWindowListener;
		this.mContext = context;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		conentView = inflater.inflate(R.layout.popup_addcourse, null);
		//int h = context.getWindowManager().getDefaultDisplay().getHeight();
		int w = context.getWindowManager().getDefaultDisplay().getWidth();
		this.setContentView(conentView);
		this.setWidth(w/3+110);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setOutsideTouchable(true);
		this.update();
		ColorDrawable dw = new ColorDrawable(0000000000);
		this.setBackgroundDrawable(dw);
		this.setAnimationStyle(R.style.AnimationPreview);
		LinearLayout button1 = (LinearLayout) conentView.findViewById(R.id.pop_button_01);
		LinearLayout button2 = (LinearLayout) conentView.findViewById(R.id.pop_button_02);
		LinearLayout button3 = (LinearLayout) conentView.findViewById(R.id.pop_button_03);
		LinearLayout button4 = (LinearLayout) conentView.findViewById(R.id.pop_button_04);
		button1.setOnClickListener(this);
		button2.setOnClickListener(this);
		button3.setOnClickListener(this);
		button4.setOnClickListener(this);
	}


	/**   
	 * showPopupWidow
	 * @param parent
	 */
	public void showPopupWindow(View parent) {
		if (!this.isShowing()) {
			this.showAsDropDown(parent, -5 , 5);
		} else {
			this.dismiss();
		}
	}

	@Override
	public void onClick(View v) {
		if(clickClubWindowListener!=null){
			
			switch (v.getId()) {
			case R.id.pop_button_01:
				clickClubWindowListener.onClickClubWindowListener(1,type[1]);
				break;
			case R.id.pop_button_02:
				clickClubWindowListener.onClickClubWindowListener(2,type[2]);
				
				break;
			case R.id.pop_button_03:
				clickClubWindowListener.onClickClubWindowListener(3,type[3]);
				break;
			case R.id.pop_button_04:
				clickClubWindowListener.onClickClubWindowListener(4,type[4]);
				
				break;
			default:
				break;
			}
		}
		
		
		ClubWindow.this.dismiss();
	}}